package com.rainbow.service;

import com.rainbow.config.RestConfig;
import com.rainbow.domain.Product;
//import com.rainbow.service.fallback.ProductServiceFallbackFactory;
//import com.rainbow.service.fallback.ProductServiceFallback;
import com.rainbow.service.fallback.ProductServiceFallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

//        // 调用商品微服务 查询商品
//        List<ServiceInstance> instances = discoveryClient.getInstances("service-product");
// 随机
//        ServiceInstance instance = instances.get(new Random().nextInt(instances.size()));
//        // ServiceInstance instance = instances.get(0);
//        Product product = restTemplate.getForObject(instance.getUri()+"/product/" + pid,
//                Product.class);
// ribbon 负载均衡
//        Product product = restTemplate.getForObject("http://service-product/product/" + pid,
//                Product.class);
@FeignClient(value = "service-product",configuration = RestConfig.class
//        ,fallback = ProductServiceFallback.class)
        ,fallbackFactory = ProductServiceFallbackFactory.class)
public interface ProductService {

    @RequestMapping("/product/{pid}")
    Product findByPid(@PathVariable Integer pid);

    @RequestMapping(value = "/product/sale",method = RequestMethod.POST)
    String sale(@RequestParam("pid") Integer pid, @RequestParam("number") Integer number);
}
